import { useTranslation } from "react-i18next";
import Toolbar from "@/components/ViewComponents/Toolbar";
import "./index.less";
import { BasicTable, useTable, BasicColumn, FormSchema, TableAction } from "@/components/Table/index";
import { checkupgroupList } from "@/api/SecondmentDictionary";
import { useDrawer } from "@/components/Drawer";
import CreateCheckupgroup from "./components/createCheckupgroup/index";
import LeagueMember from "./components/leagueMember/index";
import Examination from "./components/examination";

export default function general_health() {
	const { t } = useTranslation();
	let btnList = [
		{
			key: "add",
			text: "add"
		}
	];
	const leftTopTable_columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			dataIndex: "grpId" //团队编号
		},
		{
			title: t("felix_ui.grp_unit"),
			dataIndex: "grpName", //名称
			width: 160
		},
		{
			title: t("felix_ui.date_from"),
			dataIndex: "contractId" //合同编号
		},
		{
			title: t("felix_ui.date_to"),
			dataIndex: "dtDate", //合同日期
			render: text => {
				if (text) {
					return text.map((item: number, index: number) => {
						if (index === text.length - 1) return item;
						return "" + item + "-";
					});
				}
				return "";
			}
		},
		{
			title: t("felix_ui.date_to"),
			dataIndex: "grpAddr" //地址
		},

		{
			title: t("felix_ui.date_to"),
			dataIndex: "phoneNumb" //电话号码
		},
		{
			title: t("felix_ui.date_to"),
			dataIndex: "grpTin" //税号
		},
		{
			title: t("felix_ui.date_to"),
			dataIndex: "contactPersonId" //联系人
		},
		{
			title: t("kevin_ui.operate"),
			fixed: "right",
			render: (_, record) => (
				<TableAction
					actions={[
						{
							label: t("kevin_ui.leagueMember"),
							onClick: staffFn(record)
						},
						{
							label: t("kevin_ui.examination"),
							onClick: examinationFn(record)
						}
					]}
				></TableAction>
			)
		}
	];
	const formItemsSchema: FormSchema[] = [
		{
			label: t("felix_ui.grp_name"),
			field: "grpName", //名称
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.contract_numb"),
			field: "contractId", //合同号
			component: "Input",
			colProps: { span: 6 }
		},

		{
			label: t("felix_ui.grp_type"),
			field: "grpType", //类型：1.门诊，2.住院
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.grp_addr"),
			field: "grpAddr", //地址
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.grp_subject"),
			field: "grpSubject",
			component: "Select",
			componentProps: {
				options: [
					{ label: "1.Agency Medical Check-up", value: "1" },
					{ label: "2. Periodic Health Check-up", value: "2" },
					{ label: "3. Group Health Check-up", value: "3" },
					{ label: "4. Health Examination", value: "4" },
					{ label: "5. Paid Health Check-up", value: "5" },
					{ label: "6. CV 5028-NN", value: "6" },
					{ label: "7. CV 5029-NV", value: "7" }
				]
			},
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.grp_fax"),
			field: "grpFax", //传真
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.grp_email"),
			field: "grpEmail", //电子邮件
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.grp_tin"),
			field: "grpTin", //税号
			component: "Input",
			colProps: { span: 6 }
		}
	];

	const [registerDrawer, { openDrawer: creata }] = useDrawer();
	const [LeagueMembeRegisterr, { openDrawer: LeagueMembeOpenDrawer }] = useDrawer();
	const [ExaminationRegisterr, { openDrawer: ExaminationOpenDrawer }] = useDrawer();
	const [leftTopTable, { reload }] = useTable({
		api: checkupgroupList,
		columns: leftTopTable_columns,
		bordered: true,
		useSearchForm: true,
		formConfig: {
			schemas: formItemsSchema,
			showActionButtonGroup: true,
			labelWidth: 100,
			actionColOptions: { span: 24 }
		}
	});

	const staffFn =
		({ grpId }: any) =>
		() => {
			LeagueMembeOpenDrawer(true, {
				grpId
			});
		};
	const examinationFn =
		({ grpId }: any) =>
		() => {
			ExaminationOpenDrawer(true, {
				grpId
			});
		};

	const handlerToolbarAction = (key: string) => {
		switch (key) {
			case "add":
				creata(true, {
					reload
				});
				break;
		}
	};

	return (
		<div className="general_health page">
			<div className="page-content">
				<BasicTable register={leftTopTable}></BasicTable>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={btnList} />
			<CreateCheckupgroup register={registerDrawer}></CreateCheckupgroup>
			<LeagueMember register={LeagueMembeRegisterr}></LeagueMember>
			<Examination register={ExaminationRegisterr}></Examination>
		</div>
	);
}
